home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
LDB171.ARJ
/
MUTUAL.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-12
|
11KB
|
444 lines
/*
mutual.hpp -- Loose Data Binder v 1.7:
mutually owned and persistence
(C) Copyright 1992 John W. Small
All rights reserved
PSW / Power SoftWare
P.O. Box 10072
McLean, Virginia 22102 8072 USA
(703) 759-3838
*/
#ifndef Mutual_HPP
#define Mutual_HPP
#include <iostream.h>
#include <iomanip.h>
#ifndef Binder_HPP
#include "binder.hpp"
#endif
#define ID_Mutual 0
#define ID_MRef ID_Mutual
#define ID_MBinder 1
typedef class Mutual * MutuaL;
#define MutuaL0 ((MutuaL)0)
typedef initVFTs initMutual;
#define initVFTsEtc initVFTsOnly
class Mutual {
private:
friend class StreamRegistry;
voiD parenT;
unsigned refCount, streamCount;
long streamPos;
protected:
Mutual (initMutual);
static void serror(const char *msg, unsigned id);
virtual void error(const char *msg);
virtual void warn(const char *msg);
virtual void fput(ostream&) {}
static MutuaL fget(istream&, MutuaL InstancE)
{ return InstancE; }
public:
static int refDebug, streamDebug;
static char memberTermChar;
Mutual (Mutual&) { Mutual(initVFTsEtc); }
static void RegisterClass(unsigned id,
MutuaL (*fgeT)(istream&, MutuaL));
virtual int operator=(Mutual&) { return 0; }
virtual MutuaL clone() { return MutuaL0; }
voiD ParenT() { return parenT; }
virtual unsigned ID() { return ID_Mutual; }
virtual unsigned restream();
void unlink(voiD P = voiD0);
int link(voiD P = voiD0);
unsigned RefCount() { return refCount; }
long StreamPos() { return streamPos; }
virtual ~Mutual() {}
};
typedef class MBinder * MBindeR;
#define MBindeR0 ((MBindeR)0)
class MBinder : Binder, public Mutual {
protected:
MBinder (initVFTs)
: Binder(initVFTsOnly),
Mutual(initVFTsEtc) {}
Binder:: destruct;
virtual voiD Dassign(voiD D, const voiD S);
virtual voiD Dnew(const voiD D);
virtual void Ddelete(voiD D);
virtual int Dattach(voiD D)
{ return ((MutuaL)D)->link(this); }
virtual void Ddetach(voiD D)
{ ((MutuaL)D)->unlink(this); }
Binder:: sberror;
Binder:: berror;
virtual void Dstore(ostream& os, voiD D);
virtual voiD Dload(istream& is);
Binder:: store;
static MBindeR load(istream& is, MBindeR thiS);
Binder:: vload;
virtual void fput(ostream& os) { store(os); }
static MutuaL fget(istream& is, MutuaL InstancE)
{ return (MutuaL)
load(is,(MBindeR)InstancE); }
public:
/* Constructors and destructor */
MBinder (unsigned flags = BDR_DDELETE | BDR_DSTORE,
unsigned maxNodes = BDR_MAXNODES,
unsigned limit = BDR_LIMIT,
unsigned delta = BDR_DELTA) :
Binder(flags,maxNodes,limit,delta),
Mutual(initVFTsEtc) {}
MBinder (MutuaL argv[],
unsigned argc = 0,
unsigned flags = BDR_BIND_ONLY)
: Binder((voiDV)argv,argc,flags),
Mutual(initVFTsEtc) {}
MBinder (const char *filename)
: Binder(initVFTsOnly),
Mutual(initVFTsEtc)
{ (void) vload(filename,(BDRsloaD)
MBinder::load,this); }
int save(const char *filename)
{ return ((!RefCount())? Binder::
save(filename) : 0); }
MutuaL* vector()
{ return (MutuaL*)Binder::
vector(); }
virtual ~MBinder() { MBinder::destruct(); }
static void RegisterClass()
{ Mutual::RegisterClass(ID_MBinder,
MBinder::fget); }
virtual unsigned ID() { return ID_MBinder; }
virtual unsigned restream();
/* Housekeeping Primitives */
Binder:: Limit;
Binder:: setLimit;
Binder:: pack;
Binder:: Delta;
Binder:: setDelta;
Binder:: Nodes;
Binder:: MaxNodes;
Binder:: setMaxNodes;
Binder:: vacancy;
Binder:: vacancyNonElastic;
Binder:: Flags;
Binder:: setFlags;
Binder:: resetFlags;
MBinder& operator<<(MBinder& (*manipulator)
(MBinder&)) { return
(manipulator? (*manipulator)
(*this) : *this); }
/* Elastic Array Primitives */
MutuaL atIns(unsigned n, MutuaL D)
{ return (MutuaL)Binder::
atIns(n,(voiD)D); }
MutuaL atInsNew(unsigned n, const MutuaL D)
{ return (MutuaL)Binder::
atInsNew(n,(const voiD)D); }
MutuaL atRmv(unsigned n)
{ return (MutuaL)Binder::
atRmv(n); }
Binder:: allRmv;
Binder:: atDel;
MutuaL atDelAsg(unsigned n, MutuaL D)
{ return (MutuaL)Binder::
atDelAsg(n,(voiD)D); }
Binder:: allDel;
MutuaL atPut(unsigned n, MutuaL D)
{ return (MutuaL)Binder::
atPut(n,(voiD)D); }
MutuaL atPutNew(unsigned n, const MutuaL D)
{ return (MutuaL)Binder::
atPutNew(n,(const voiD)D); }
MutuaL atPutAsg(unsigned n, const MutuaL D)
{ return (MutuaL)Binder::
atPutAsg(n,(const voiD)D); }
MutuaL atGet(unsigned n)
{ return (MutuaL)Binder::
atGet(n); }
MutuaL operator[](unsigned n)
{ return atGet(n); }
MutuaL atGetAsg(unsigned n, MutuaL D)
{ return (MutuaL)Binder::
atGetAsg(n,(voiD) D); }
MutuaL atXchg(unsigned n, MutuaL D)
{ return (MutuaL)Binder::
atXchg(n,(voiD) D); }
unsigned index(const MutuaL D)
{ return Binder::
index((const voiD)D); }
Binder:: forEach;
/* Stack - Deque - Queue Primitives */
MutuaL push(MutuaL D)
{ return (MutuaL)Binder::
push((voiD) D); }
MutuaL pushNew(const MutuaL D)
{ return (MutuaL)Binder::
pushNew((const voiD)D); }
MutuaL pop()
{ return (MutuaL)Binder::
pop(); }
MBinder& operator>>(MutuaL& D)
{ D = atRmv(0); return *this; }
Binder:: popDel;
MutuaL popDelAsg(MutuaL D)
{ return (MutuaL)Binder::
popDelAsg((voiD)D); }
MutuaL top()
{ return (MutuaL)Binder::
top(); }
MutuaL topAsg(MutuaL D)
{ return (MutuaL)Binder::
topAsg((voiD)D); }
MutuaL insQ(MutuaL D)
{ return (MutuaL)Binder::
insQ((voiD)D); }
MBinder& operator<<(MutuaL D)
{ atIns(Nodes(),D); return *this; }
MutuaL insQNew(const MutuaL D)
{ return (MutuaL)Binder::
insQNew((const voiD)D); }
MutuaL unQ()
{ return (MutuaL)Binder::
unQ(); }
Binder:: unQDel;
MutuaL unQDelAsg(MutuaL D)
{ return (MutuaL)Binder::
unQDelAsg((voiD)D); }
MutuaL rear()
{ return (MutuaL)Binder::
rear(); }
MutuaL rearAsg(MutuaL D)
{ return (MutuaL)Binder::
rearAsg((voiD)D); }
/* List (single and double linked) Primitives */
Binder:: CurNode;
Binder:: setCurNode;
MutuaL ins(MutuaL D)
{ return (MutuaL)Binder::
ins((voiD)D); }
MutuaL insNew(const MutuaL D)
{ return (MutuaL)Binder::
insNew((const voiD)D); }
MutuaL rmv()
{ return (MutuaL)Binder::
rmv(); }
Binder:: del;
MutuaL delAsg(MutuaL D)
{ return (MutuaL)Binder::
delAsg((voiD)D); }
MutuaL put(MutuaL D)
{ return (MutuaL)Binder::
put((voiD)D); }
MutuaL putNew(const MutuaL D)
{ return (MutuaL)Binder::
putNew((const voiD)D); }
MutuaL putAsg(const MutuaL D)
{ return (MutuaL)Binder::
putAsg((const voiD)D); }
MutuaL get()
{ return (MutuaL)Binder::
get(); }
operator MutuaL() { return get(); }
MutuaL getAsg(MutuaL D)
{ return (MutuaL)Binder::
getAsg((voiD)D); }
MutuaL next()
{ return (MutuaL)Binder::
next(); }
MutuaL operator++()
{ return next(); }
MutuaL nextAsg(MutuaL D)
{ return (MutuaL)Binder::
nextAsg((voiD)D); }
MutuaL prev()
{ return (MutuaL)Binder::
prev(); }
MutuaL operator--()
{ return prev(); }
MutuaL prevAsg(MutuaL D)
{ return (MutuaL)Binder::
prevAsg((voiD)D); }
MutuaL firstThat(BDRdetecT B, voiD M = voiD0)
{ return (MutuaL)Binder::
firstThat(B,M); }
MutuaL lastThat(BDRdetecT B, voiD M = voiD0)
{ return (MutuaL)Binder::
lastThat(B,M); }
/* Priority Q, Set, Bag, Dictionary, Sort Primitives */
Binder:: Sorted;
Binder:: unSort;
Binder:: setComP;
Binder:: ComP;
Binder:: sort;
MutuaL insSort(MutuaL D)
{ return (MutuaL)Binder::
insSort((voiD)D); }
MutuaL insSortNew(const MutuaL D)
{ return (MutuaL)Binder::
insSortNew((const voiD)D); }
MutuaL insUnique(MutuaL D)
{ return (MutuaL)Binder::
insUnique((voiD)D); }
MutuaL insUniqueNew(const MutuaL D)
{ return (MutuaL)Binder::
insUniqueNew((const voiD)D); }
MutuaL findFirst(const MutuaL K)
{ return (MutuaL)Binder::
findFirst((const voiD)K); }
MutuaL findNext(const MutuaL K)
{ return (MutuaL)Binder::
findNext((const voiD)K); }
MutuaL findLast (const MutuaL K)
{ return (MutuaL)Binder::
findLast((const voiD)K); }
MutuaL findPrev(const MutuaL K)
{ return (MutuaL)Binder::
findPrev((const voiD)K); }
unsigned findAll(const MutuaL K)
{ return Binder::
findAll((const voiD)K); }
}; /* class MBinder */
typedef void (*GenericFnC)();
#define GenericFnC0 ((GenericFnC)0)
#define ID_UnknownGenericFnC 0
class StreamRegistry {
private:
Binder ClassRecords;
Binder InstanceRecords;
Binder FunctionRecords;
protected:
void CIerror(char *msg, unsigned id = 0,
MutuaL InstancE = MutuaL0);
void CIwarn(char *msg, unsigned id = 0,
MutuaL InstancE = MutuaL0);
void FNCerror(char *msg, unsigned id);
void FNCwarn(char *msg, unsigned id);
public:
static int debug;
StreamRegistry() :
ClassRecords(BDR_DDELETE),
InstanceRecords(BDR_DDELETE),
FunctionRecords(BDR_DDELETE)
{}
unsigned restream();
void RegisterClass(unsigned id,
MutuaL (*fgeT)(istream&, MutuaL));
void registerFunction(unsigned id, GenericFnC fnC);
GenericFnC fnCLU(unsigned id);
unsigned fnCID(GenericFnC fnC);
void forgetRegistrations();
void fput(ostream& os, Mutual& Instance);
void fget(istream& is, MutuaL& InstancE);
~StreamRegistry() {}
};
extern StreamRegistry StreamReg;
#define Restream() StreamReg.restream()
#define RegisterFunction(id,fnC) \
StreamReg.registerFunction(id,(GenericFnC)fnC)
#define fnC2ID(fnC) StreamReg.fnCID((GenericFnC)fnC)
#define ID2fnC(fnCType,id) (fnCType) StreamReg.fnCLU(id)
#define ForgetRegistrations() \
StreamReg.forgetRegistrations()
inline ostream& operator<<(ostream& os, Mutual& m)
{
StreamReg.fput(os,m);
return os;
}
inline istream& operator>>(istream& is, MutuaL& M)
{
StreamReg.fget(is,M);
return is;
}
inline ostream& operator<<(ostream& os, MBinder& b)
{
if (b.Flags(BDR_DSTORE))
os << *(MutuaL)&b;
return os;
}
extern ostream& Mendm(ostream& os);
extern istream& Mnextm(istream& is);
#endif /* Mutual_HPP */